package com.zl.common.enumType;

import java.util.Calendar;
import java.util.Date;

/** 
* @ClassName: PublicDate 
* @Description: 发布日期枚举类
* @author chxl
* @date 2015-5-27 上午11:21:34 
*  
*/
public enum PublicDate {
	ALLDATE("全部日期",1),
	ONEDAY("最近一天",2),
	THREEDAY("最近三天",3),
	ONEWEEK("最近一周",4),
	ONEMONTH("最近一月",5),
	ONEYEAR("最近一年",6);

	private String name;
	private int ordinal;
	private Date startDate;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public int getOrdinal() {
		return ordinal;
	}


	public void setOrdinal(int ordinal) {
		this.ordinal = ordinal;
	}


	public Date getStartDate() {
		return startDate;
	}


	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}


	private PublicDate(String name, int ordinal) {
		Calendar now = Calendar.getInstance();
		
		switch(ordinal){
			case 1: 
				now.set(Calendar.YEAR,now.get(Calendar.YEAR)-3);
				break;
			case 2: 
				now.set(Calendar.DATE,now.get(Calendar.DATE)-1);
				break;
			case 3: 
				now.set(Calendar.DATE,now.get(Calendar.DATE)-3);
				break;
			case 4: 
				now.set(Calendar.DATE,now.get(Calendar.DATE)-7);
				break;
			case 5: 
				now.set(Calendar.MONTH,now.get(Calendar.MONTH)-1);
				break;
			case 6: 
				now.set(Calendar.YEAR,now.get(Calendar.YEAR)-1);
				break;
			default:
		}
		this.startDate = now.getTime();	
		this.name = name;
		this.ordinal = ordinal;
	}
	
	public static PublicDate getDateByOrdinal(int ordinal){
		for(PublicDate t:PublicDate.values()){
			if(t.getOrdinal()==ordinal){
				return t;
			}
		}
		return null;
	}
	
}
